var MenuItemRender = new Class({
	"Extends":js.underas.controller.ListViewItemRender
	,"initialize":function(p_obj){	
		var htmlTmp = '<h4><span class="glyphicon glyphicon-'+p_obj.icone+'"></span>'+p_obj.label+'</h4>';
		htmlTmp += '<p class="list-group-item-text">ICONE:'+p_obj.icone+'</p>'; 
		htmlTmp += '<p class="list-group-item-text">ORDEM:'+p_obj.ordem+'</p>'; 
		this.parent('div',htmlTmp);
		this.getEle().addClass("col-xs-6 col-sm-4 col-md-4");
		}
	});



var Menu = new Class({
	"Extends":js.underas.container.ModWindow
	,"itIdMenu":null	 
	,"itLabel":null	 
	,"itIcone":null	 
	,"itOrdem":null	 
	,"initialize":function(){
		this.parent("*cadastro e configuracao dos menus.");
		this.setRevision("$Revision: 143 $");		
		this.setSize(5);

		this.itIdMenu = new js.underas.controller.InputText("");
		this.itIdMenu.setColumn("$_id");
		this.itIdMenu.setLabel("cod.");
		this.itIdMenu.setEnable(false);	
		this.itIdMenu.setSize(3);	
		this.append(this.itIdMenu);	

		this.itLabel = new js.underas.controller.InputText("");
		this.itLabel.setColumn("@label");
		this.itLabel.setLabel("label");
		this.itLabel.setSize(6);	
		this.append(this.itLabel);		



		this.itOrdem = new js.underas.controller.NumericStepper(0);
		this.itOrdem.setColumn("@ordem");
		this.itOrdem.setLabel("ordem");
		this.itOrdem.setSize(3);	
		this.itOrdem.setMin(1);
		this.itOrdem.setMax(100);
		this.itOrdem.setStep(1);
		this.itOrdem.setEnable(false,2);
		this.append(this.itOrdem);

		this.itIcone = new js.underas.controller.Select("selecione um icone");
		this.itIcone.setLabel("icone");
		this.itIcone.setColumn("@icone");
		this.itIcone.setSize(12);
		this.itIcone.setValueField("icon");
		this.itIcone.setLabelField("desc");
		this.append(this.itIcone);	
		
		this.mainList = new js.underas.controller.ListView("Menu");
		this.mainList.setItemRender("MenuItemRender");
		//this.setMainList("mainList");
		this.mainTb = new js.underas.net.ToolBar({"domain":"perfil/menu"});
		this.append(this.mainTb);			
		this.append(this.mainList);		
		this.addAssociation({"mod":"br.net.atasacramental.menu.view.ItemMenu","embed":"children","puid":this.getVarModule()});
	}
	,"onStart":function(){
		//this.mainTb.activate(true);
		this.itIcone.fromService("assets/icons.json");	
		//this.mainTb.reloadItens();
	}
	,"beforeInsert":function(p_obj){
		p_obj["url"]="/perfil/menu/"+ perfil.itIdPerfil.getValue();
		//p_obj["method"]="post";
		return p_obj;
	}
	,"beforeUpdate":function(p_req,p_old_obj){
		p_req["url"]="/perfil/menu/"+ perfil.itIdPerfil.getValue();
		//p_req["method"]="put";
		//console.log(p_old_obj);
		if(p_old_obj.children){
			p_req.data["children"] = [];
			p_req.data["children"] = p_old_obj.children;
		};
		return p_req;
	}
	,"beforeDelete":function(p_new_obj,p_old_obj){
		p_new_obj["url"]="/perfil/menu/"+ perfil.itIdPerfil.getValue() + "," + p_old_obj._id;
		//p_new_obj["method"]="delete";
		return p_new_obj;
	}
});